/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       town_list_window.h

	$Header: /game/town_list_window.h $

	$NoKeywords: $

 ************************************************************************/

#ifndef TOWN_LIST_WINDOW_H_INCLUDED
#define TOWN_LIST_WINDOW_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <vector>
#include "bitmap_group_ptr.h"
#include "bitmap_layer_ptr.h"
#include "buffer_window_ptr.h"
#include "game_window.h"
#include "handler.h"
#include "list_viewer.h"
#include "scrollbar_ptr.h"
#include "shared_ptr.h"
#include "town_list_ptr.h"
#include "town_ptr.h"

class t_adv_object_list_image;
class t_adventure_map;
class t_bitmap_layer;
class t_button;
class t_micro_map_window;

typedef t_handler_1<t_town*> t_town_select_handler;

// ----------------------------------------------------------------------
// display a list of armies
// ----------------------------------------------------------------------
class t_town_list_window : public t_window, public t_list_viewer 
{
public:
	t_town_list_window( t_screen_rect const& rect, t_window* parent, bool use_small_bitmaps = false );
	virtual ~t_town_list_window();

	void         attach( t_scrollbar* scrollbar );
	virtual void detach();
	virtual void inserted( int index );
	t_town *	 move_selection( int step_size, bool wrap_selection = false );
	void         move_selection_and_select( int step_size, bool wrap_selection = true );
	virtual void removed( int index );
	void         set_map( t_adventure_map const& map );
	void		 set_town_list( t_town_list* list, int team_view );
	void         set_select_handler( t_town_select_handler handler );
	void         set_double_click_handler( t_town_select_handler handler );
	void         select_town( t_town* town );
	void		 update();
protected:
	void			double_click( t_button* button, int result );
	virtual void	on_visibility_change();
	void			select( t_button* button, int result );
	void			set_scrollbar();
	void			set_highlight( int index );
	void			scroll_list( t_scrollbar* scrollbar, int first_value );

	struct t_item
	{
		t_town_ptr			town;
		t_button*			button;
		t_window*			highlight_border;
		t_window*			normal_border;
		t_buffer_window*	town_image;
		t_micro_map_window* map_image;
		t_window_ptr		built_checkmark_image;
	};

	std::vector<t_adv_object_list_image>	m_town_images;
	t_adventure_map const*					m_adventure_map;
	t_bitmap_layer_ptr						m_town_marker;
	t_bitmap_group_ptr						m_bitmaps;
	std::vector<t_item>						m_items;
	t_town_list_ptr							m_towns;
	int										m_first_town;
	int										m_selected_town;
	t_town_select_handler					m_select_handler;
	t_town_select_handler					m_double_click_handler;
	t_scrollbar_ptr							m_scrollbar;
	int										m_team_view;
	t_screen_point							m_micro_map_size;
};

inline void t_town_list_window::set_select_handler( t_town_select_handler handler )
{
	m_select_handler = handler;
}

inline void t_town_list_window::set_double_click_handler( t_town_select_handler handler )
{
	m_double_click_handler = handler;
}

#endif // TOWN_LIST_WINDOW_H_INCLUDED